/* _NSPROJ_MPP_C_
 * 
 * SOLVES THREE DIMENSIONAL, INCOMPRESSIBLE NAVIER-STOKES
 * EQUATION WITH RECTANGULAR DOMAIN USING FINITE DIFFERENCING 
 * ON A STAGGERED GRID
 * UTILIZES THE PROJECTION METHOD.  THE CONSERVATIVE FORM
 * CONVECTION IS DISCRETIZED WITHOUT THE USE OF UPWIND TREATMENT; 
 * BOTH THE ADVECTION AND DIFUSSION TERMS ARE TREATED EXPLICITLY. 
 * THE CURRENT SETUP IS FOR A LID DRIVEN CAVITY PROBLEM WITH A WELL
 * KNOWN VELOCITY AT THE TOP AND NO-SLIP BOUNDARY CONDIITIONS AT
 * ALL OTHER BOUNDARIES
 * 
 * ORIGINALLY WRITTEN BY DR. ZHI-GANG FENG: UNIVERSITY OF NORTH TEXAS
 * 
 * PORTED TO C AND 3D BY JOHN LEIDEL: GRADUATE STUDENT
 * 
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include "nsproj.h"
#include "mpi.h"


//-----------------------------------------START_SIM
// START_SIM
//--------------------------------------------------
int start_sim( char *datafile, int argc, char **argv )
{
    /* VARS */
    int size   = 0;   //-- MPI_COMM size
    int rank   = 0;   //-- MPI_COMM rank
    int rtn    = 0;   //-- MPI_RTN
    int c      = 0;   //-- COUNTER 
    /* ---- */

    /* INIT MPI ENV */
    rtn = MPI_Init( &argc, &argv );
    if( rtn != MPI_SUCCESS )
    {
	fprintf( stderr, "%s\n", "ERROR : COULD  NOT INITIATE MPI ENVIRONMENT" );
	return -1;
    }

    MPI_Comm_size( MPI_COMM_WORLD, &size );
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );

    if( rank == 0 )
    {
	printf( "%s\n", "NSPROJ_MPP v. 0.1" );
    }

    /* DETERMINE GRID DISTRIBUTION */

    /* DISTRIBUTE INITIAL DATA */

    /* BEGIN SIMULATION */
    /* -- EXECUTE FIRST ITERATION */
    /* -- COLLECT DATA TO RANK = 0 */
    /* -- PERFORM I/O */
    /* -- UPDATE ALL RANKS */
    /* -- `Nth` ITERATION COMPLETE */

    return 0;
}

//-----------------------------------------MAIN
// MAIN
//---------------------------------------------
int main( int argc, char **argv )
{
    /* VARS */
    char *datafile = NULL;
    int rtn        = 0;
    /* ---- */

    if( argc < 2 )
    {
	fprintf( stderr, "%s\n", "USAGE: <mpirun> nsproj_mpp <datafile>" );
	return -1;
    }

    datafile = (char *)malloc( 1024 );
    if( datafile == NULL )
    {
	fprintf( stderr, "%s\n", "ERROR :  COULD NOT ALLOCATE MEMORY FOR DATA FILE" );
	return -1;
    }

    sprintf( datafile, "%s", argv[1] );
    
    rtn = start_sim( datafile, argc, argv );
    
    free( datafile );
    datafile = NULL;

    return rtn;
}
